package org.snail.dept.bean;

import lombok.Data;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 树节点
 */
@Data
public class TreeNode implements Serializable{
    private static final long serialVersionUID = -6172463610878658357L;

    private String id;     //本级部门id
    private String parentId;    //上级部门id
    private String name;        //部门名称
    private List<TreeNode> children;      //下级部门列表
    private TreeNode parentNode;   //上级部门全体对象
    private List<String> manager;    //部门负责人userid
    private List<String> userList;    //部门下人员
    private String ownerId;    //每个层级部门管理员id
    private List parentsList;    //底层部门属性
    /**
     * 公司部门标记
     * L0代表公司，依次往下推
     */
    private String lv;

    public String getLv() {
        return lv;
    }

    public void setLv(String lv) {
        this.lv = lv;
    }

    public List<String> getManager() {
        return manager;
    }

    public void setManager(List<String> manager) {
        this.manager = manager;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<TreeNode> getChildren() {
        return children;
    }

    public void setChildren(List<TreeNode> children) {
        this.children = children;
    }

    public TreeNode getParentNode() {
        return parentNode;
    }

    public void setParentNode(TreeNode parentNode) {
        this.parentNode = parentNode;
    }

    /**
     * 判断是否为root节点
     * @param parentId  父节点id
     * @return 返回是否父节点为根节点
     */
    public boolean isRoot(String parentId) {
        if (StringUtils.isEmpty(parentId))
            return true;
        return false;
    }

    /**
     * 添加子节点
     * @param treeNode
     */
    public void addChildNode(TreeNode treeNode) {
        initChildList();
        children.add(treeNode);
    }

    /**
     * 树节点初始化
     */
    private void initChildList() {
        if (children == null)
            children = new ArrayList();
    }

    public String getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(String ownerId) {
        this.ownerId = ownerId;
    }

    @Override
    public String toString() {
        return "id : " + id + ", name : " + name + ", lv : " + lv;
    }

}
